package com.fit.dao.scientificField;

import java.util.List;

import org.apache.tapestry5.ioc.annotations.Inject;
import org.hibernate.Session;

import com.fit.entities.ScientificField;

public class ScientificFieldDAOImpl implements ScientificFieldDAO{

	@Inject
	private Session session;
	
	public boolean save(ScientificField newScientificField) {
		if (newScientificField != null) {
			session.save(newScientificField);
			return true;
		}
		return false;
		
	}

	public boolean delete(ScientificField scientificField) {
		if (scientificField != null) {
			session.delete(scientificField);
			return true;
		}
		return false;
	}

	public boolean update(ScientificField scientificField) {
		if (scientificField != null) {
			session.update(scientificField);
			return true;
		}
		return false;
	}

	public List<ScientificField> findAll() {
		return session.createCriteria(ScientificField.class).list();
		
	}

	public ScientificField findByID(Long id) {
		if (id != null) {
			return (ScientificField) session.get(ScientificField.class, id);
		}
		return null;
	}

	public boolean deleteByID(Long id) {
		ScientificField sf = findByID(id);
		if (sf != null) {
			delete(sf);
			return true;
		}
		return false;
	}
}
